/*
 * Creator:     ML
 * CreatDate:   2019-08-20
 * descripts：  个人信息/个人设置  入口
*/
import React from 'react';
import { Tabs, Modal } from 'antd';
import store from '../../store';
import { $http } from '../../containers/config/https';
import ViewInformation from './common/ViewInformation'; // 查看资料
import ModifyUserName from './common/ModifyUserName'; // 修改用户名
import ChangePassword from './common/ChangePassword'; // 修改密码
import SettingDefaultLoginSection from './common/SettingDefaultLoginSection'; // 设置默认登录角色
import PerfectingContactWay from './common/PerfectingContactWay'; // 完善联系方式
// import ShiftSetting from './common/ShiftSetting'; // 排班设置
import SittingApply from './common/SittingApply'; // 坐诊申请
import ConsultationTemplate from './common/ConsultationTemplate'; // 咨询模板
// import SittingExamination from './common/SittingExamination'; // 坐诊审核
import PersonalAnnouncement from './common/PersonalAnnouncement'; // 个人公告
import AddAssistant from './common/AddAssistant'; // 医生助理 添加助理
import BedChartSetting from 'pages/nurseStation/BedChartSetting'; // 床位图-通用设置
import BedChartIconSetting from 'pages/nurseStation/BedChartIconSetting'; // 床位图-图标设置

const TabPane = Tabs.TabPane;
class UserInfomation extends React.Component {
  constructor(porps) {
    super(porps);
    this.state = {
      activeKey: '1',
      userInfo: {}, //用户数据
      visible: false,//是否弹个人信息
      localeProvider: []
    }
  }

  componentDidMount() {
    this.props.OnChildrefs(this);
    if (document.querySelector('.ant-drawer')) {
      document.querySelector('.ant-drawer').style.zIndex = "9999"
    }
  }

  // PersonalInformation	
  onView = (ref) => {
    this.onChildView = ref
  }

  onModifyUserName = (ref) => {
    this.onChildModifyUserName = ref
  }

  onChangePassword = (ref) => {
    this.onChildChangePassword = ref
  }

  onSettingDefaultLoginSection = (ref) => {
    this.onChildSettingDefaultLoginSection = ref
  }

  onPerfectingContactWay = (ref) => {
    this.onChildPerfectingContactWay = ref
  }

  onSittingApply = (ref) => {
    this.onChildSittingApply = ref
  }

  onShiftSetting = (ref) => {
    this.onChildonShiftSetting = ref
  }

  onConsultationTemplate = (ref) => {
    this.onChildConsultationTemplate = ref
  }

  onPersonalAnnouncement = (ref) => {
    this.onChildPersonalAnnouncement = ref
  }

  onAddAssistant = (ref) => {
    this.onChildAddAssistant = ref
  }

  handleHomeData = (name) => {
    let obj = {
      "1": () => {
        this.onChildView.getInfo()
        this.onChildView.loginMetods()
      },
      "2": () => {
        this.onChildModifyUserName.getUserName()
      },
      "3": () => {
        // this.onChildChangePassword.getUserName()
      },
      "4": () => {
        this.onChildSettingDefaultLoginSection.getLoc()
      }, "5": () => {
        this.onChildPerfectingContactWay.getType()
        this.onChildPerfectingContactWay.getTypeTable()
      }, "6": () => {
        this.onChildSittingApply.getBaseParams()
        this.onChildSittingApply.getIconUrl()
      }, "7": () => {
        this.handleIsApply()
        this.onChildonShiftSetting.loginTencent()
      }, "8": () => {
        this.onChildConsultationTemplate.getData()
        // this.onChildConsultationTemplate.onInitData()
        // this.onChildConsultationTemplate.handleShiftType()
      },
      "9": () => {
        this.onChildPersonalAnnouncement.getData()
      },
      "10": () => {
        this.onChildAddAssistant.getData()
      }
    }
    if (obj[name]) {
      obj[name]()
    }
  }

  handleIsApply = () => {
    let userData = JSON.parse(sessionStorage.getItem('userData'));
    let data = {
      params: [{
        userID: userData && userData.userID || "",
        locID: userData && userData.locID || ""
      }]
    }
    $http.post('urlS', this, {
      code: '03100009',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          this.onChildonShiftSetting.handleIsApplyTips(res.result, res.statusCode, res.statusDesc)
        }
      }
    })
  }

  // 导航栏切换
  callback = (key) => {
    this.setState({ activeKey: key }, () => {
      this.handleHomeData(key)
      if (key != "7" && this.onChildonShiftSetting) {
        this.onChildonShiftSetting.signOut("User")
      }
    })
  }

  // 获取主列表columns
  getMainTableColumns = () => {
    let userData = JSON.parse(sessionStorage.getItem('userData'));
    let data = {
      params: [{
        compontName: "PersonalInformation", // 医嘱查询coll表头
        reactCode: ['PersonalInformation'],
        type: 'C',
      }]
    }
    $http.post('urlS', this, {
      code: '01040073',
      data: data,
      success: function (res) {
        if (+res.errorCode === 0) {
          //   let arr = res.result && res.result.C.length > 0 ? JSON.parse(JSON.stringify(res.result.C)).map(item => {
          //     return {
          //       align: item.align,
          //       widthNum: parseInt(item.width),
          //       width: item.width,
          //       dataIndex: item.dataIndex,
          //       title: <div onDoubleClick={() => this.columnRef.onOpenModel()}>{this.state.userData.language == 'EN' ? item.enDescripts : item.title}</div>,
          //       display: item.display,
          //       key: item.seqNo
          //     }
          //   }) : '';
          //   let filterArr = arr.filter(function (item) { return item.display === 'Y' });
          this.setState({
            localeProvider: userData.language == 'EN' ? res.result.language.EN : res.result.language.CN
          }, () => {
            // console.log("----",this.state.localeProvider)
            // this.props.getDec(this.state.localeProvider)
          })
        }
      }
    })
  }

  redireBack = () => {
    // this.props.history.goBack()
    let routerData = store.getState().otherData.routerData;
    let path = '';
    for (var i = 0; i < routerData.length; i++) {
      if (routerData[i].title === '用户信息') {
        path = routerData[i].path;
        break;
      }
    }
    // console.log(routerData)
    this.props.history.push(path);
  }

  //展示弹窗
  showModal = () => {
    this.setState({
      visible: true,
      activeKey: "1",
    }, () => {
      this.getMainTableColumns();
      // this.handleHomeData("1");
      setTimeout(() => {
        this.handleHomeData("1");
      }, 300);
    });
  }

  //关闭关联信息弹窗
  handleCancel = () => {
    this.setState({
      visible: false,
    }, () => {
      if (this.onChildonShiftSetting) {
        this.onChildonShiftSetting.signOut("User");
      }
    })
  }

  render() {
    return (
      <div className="user-dom">
        <Modal
          title={this.state.localeProvider && this.state.localeProvider.PersonalInformationPersonalCenter ? this.state.localeProvider.PersonalInformationPersonalCenter.descripts : "个人设置"}
          visible={this.state.visible}
          // onOk={this.handleOk}
          onCancel={this.handleCancel}
          pagination='false'
          footer={null}
          className={this.state.activeKey == "6" && document.body.clientWidth < 1400 ?
            "apply-dom user-information userInfoDomLimited" : this.state.activeKey == "6" ?
              "apply-dom user-information" : document.body.clientWidth < 1400 ?
                "userInfoDomLimited user-information" : "user-information"}

        >
          <Tabs
            activeKey={this.state.activeKey}
            onChange={this.callback}
            tabPosition="left"
            type="card"
            className="new_department_tabs"
            style={{
              width: '100%', height: store.getState().tableHeight.y + 156 + 'px', overflow: "auto",
            }}
          >
            <TabPane
              disabled
              className="title-tab"
              tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationBasicPersonalInformation ? this.state.localeProvider.PersonalInformationBasicPersonalInformation.descripts : "个人基本信息"}
            >
            </TabPane>
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationCheckingData ? this.state.localeProvider.PersonalInformationCheckingData.descripts : "基本资料"} key="1">
              <ViewInformation localeProvider={this.state.localeProvider} onView={this.onView} />
            </TabPane>
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationModifyUsername ? this.state.localeProvider.PersonalInformationModifyUsername.descripts : "修改用户名"} key="2">
              <ModifyUserName localeProvider={this.state.localeProvider} onModifyUserName={this.onModifyUserName} />
            </TabPane>
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationChangePassword ? this.state.localeProvider.PersonalInformationChangePassword.descripts : "修改密码"} key="3">
              <ChangePassword localeProvider={this.state.localeProvider} onChangePassword={this.onChangePassword} />
            </TabPane>
            <TabPane
              key="4"
              tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationSetTheDefaultLoginRole ? this.state.localeProvider.PersonalInformationSetTheDefaultLoginRole.descripts : "设置默认登录角色"}
            >
              <SettingDefaultLoginSection localeProvider={this.state.localeProvider} onSettingDefaultLoginSection={this.onSettingDefaultLoginSection} />
            </TabPane>
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationImproveContact ? this.state.localeProvider.PersonalInformationImproveContact.descripts : "完善联系方式"} key="5">
              <PerfectingContactWay localeProvider={this.state.localeProvider} onPerfectingContactWay={this.onPerfectingContactWay} />
            </TabPane>
            {/* 坐诊审核 */}
            {/* <TabPane tab={this.state.localeProvider&&this.state.localeProvider.PersonalInformationImproveExamination?this.state.localeProvider.PersonalInformationImproveExamination.descripts:"坐诊审核"}  key="6">
                        <SittingExamination localeProvider={this.state.localeProvider}/>
                    </TabPane>
                    */}
            {/* <TabPane title="互联网坐诊">
            </TabPane> */}
            <TabPane
              disabled
              className="title-tab"
              tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationInternetSitting ? this.state.localeProvider.PersonalInformationInternetSitting.descripts : "互联网坐诊"}
            >
            </TabPane>
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationSittingApply ? this.state.localeProvider.PersonalInformationSittingApply.descripts : "坐诊申请"} key="6">
              <SittingApply localeProvider={this.state.localeProvider} onSittingApply={this.onSittingApply} handleHomeData={this.callback} />
            </TabPane>
            {/* <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationImproveShiftSetting ? this.state.localeProvider.PersonalInformationImproveShiftSetting.descripts : "排班设置"} key="7">
              <ShiftSetting localeProvider={this.state.localeProvider} onShiftSetting={this.onShiftSetting}  handleHomeData={this.callback}/>
            </TabPane> */}
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationConsultationTemplate ? this.state.localeProvider.PersonalInformationConsultationTemplate.descripts : "快捷回复模板"} key="8">
              <ConsultationTemplate localeProvider={this.state.localeProvider} onConsultationTemplate={this.onConsultationTemplate} />
            </TabPane>
            <TabPane tab={this.state.localeProvider && this.state.localeProvider.PersonalInformationPersonalAnnouncement ?
              this.state.localeProvider.PersonalInformationPersonalAnnouncement.descripts : "个人公告"} key="9">
              <PersonalAnnouncement localeProvider={this.state.localeProvider} onPersonalAnnouncement={this.onPersonalAnnouncement} />
            </TabPane>
            <TabPane disabled className="title-tab" tab={"医生助理"}></TabPane>
            <TabPane tab={"添加助理"} key="10">
              <AddAssistant localeProvider={this.state.localeProvider} onAddAssistant={this.onAddAssistant} />
            </TabPane>
            <TabPane disabled className="title-tab" tab="床位图设置"></TabPane>
            <TabPane tab="通用设置" key="11">
              <BedChartSetting />
            </TabPane>
            <TabPane tab="床位图图标" key="12">
              <BedChartIconSetting />
            </TabPane>
          </Tabs>
        </Modal>
      </div>
    )
  }
};

export default UserInfomation